package com.ncs.base.task.job;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.ncs.base.common.rule.DateUtil;
import com.ncs.base.task.entity.TimeTaskEntity;
import com.ncs.base.task.entity.UserMasterEntity;
import com.ncs.base.task.service.TimedTaskService;
import com.ncs.base.task.service.UserMasterService;
import com.ncs.base.task.service.UserSalveService;
import com.vip.saturn.job.AbstractSaturnJavaJob;
import com.vip.saturn.job.SaturnJobExecutionContext;
import com.vip.saturn.job.SaturnJobReturn;

public class DemoJob extends AbstractSaturnJavaJob {

	@Autowired
	private UserMasterService userMasterService;
	@Autowired
	private UserSalveService userSalveService;
	
	@Autowired
	private TimedTaskService timedTaskService;
	
	@Override
	public SaturnJobReturn handleJavaJob(String jobName, Integer shardItem, String shardParam,
			SaturnJobExecutionContext shardingContext) throws InterruptedException {
		
		TimeTaskEntity timedTask = new TimeTaskEntity();
		timedTask.setTaskId(1);
        timedTask.setCron(DateUtil.timeToCron("2021-12-01 00:00:00"));
        timedTask.setName("李四");
        timedTask.setJobGroup("remind");
        timedTask.setCreateTime(new Date());
        timedTask.setDeleteFlag(0);
        timedTaskService.insert(timedTask);
        
        
        
		String table = shardingContext.getJobName();
		String jobParameter = shardingContext.getJobParameter();
		List<UserMasterEntity> getuser = userMasterService.getuser(table);
		System.out.println("获取主表数据:"+table+"的"+getuser.size());
		
		userSalveService.SaveUserMasterList(getuser,table);
		System.out.println("插入从表数据:"+table+"的111");
		
		
		
		//结束时间
		timedTask.setUpdateTime(new Date());
		timedTaskService.insertOrUpdate(timedTask);
		// TODO Auto-generated method stub
		return new SaturnJobReturn("I am the return result of shard item " + shardItem);
	}

}
